<template>
   <div>
    <el-form  :model="model" label-width="80px" :rules="rulesForm" ref="dataForm">
                <el-form-item label="岗位编码" class="box-Input-mini" prop="post_code">
                    <el-input v-model="model.post_code" placeholder="请输入负责人" clearable autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="岗位名称" prop="post_name" class="box-Input-mini">
                    <el-input v-model="model.post_name" placeholder="请输入部门名称" clearable autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="岗位排序" class="box-Input-mini" prop="post_sort">
                    <el-input-number v-model="model.post_sort" :min="1" :max="10" label="描述文字"></el-input-number>
                </el-form-item>
                <el-form-item label="岗位状态" >
                <el-radio-group v-model="model.status">
                    <el-radio :label="0" >正常</el-radio>
                    <el-radio :label="1">停用</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="备注">
                    <el-input type="textarea" v-model="model.remark"></el-input>
            </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
        <el-button  style="padding:10px 25px;margin-right:10px;" size="samll" @click="Closedialog">取 消</el-button>
                
        <el-button style="padding:10px 25px;" size="samll" slot="reference" @click="save" type="primary">提 交</el-button>
    </div>
  </div>
</template>

<script>
export default {
  props:{
    model:{
        type:Object, //类型
        required:true, //必要性
    },
    isUpdate:{
        type:Boolean, //类型
        required:true, //必要性
    },
  },
  data(){
    return{
        rulesForm:{
            post_code:[{ required : true, message:'请输入岗位编码', trigger:'blur'}],
            post_sort:[{ required : true, message:'请选择岗位排序', trigger:'change'}],
            post_name:[{ required : true, message:'请输入岗位名称', trigger:'blur'}],
        },
    }
  },
  methods:{
    Closedialog(){
        this.$emit('Closedialog')
    },
    save(){
        this.$refs.dataForm.validate((valid) => {
            if (valid) {
                if(this.isUpdate)
                {
                    const loading =this.$loading();
                    this.$http.putForm('/api/PostManage',{model:this.model})
                    .then(res =>{
                        console.log(res);
                         if(res.data.code == 200){
                             this.ShowMsg(res.data.msg,'success');
                             this.$emit('dataBind');
                             this.Closedialog();
                        }
                    })
                    .catch(err =>{
                        this.ShowMsg('服务器异常','error');
                    }).finally(()=>{
                            setTimeout(()=>{
                                loading.close();
                            },500);
                     })
                }
                else{
                    console.log(1111);
                    const loading =this.$loading();
                    this.$http.postForm('/api/PostManage',{model:this.model})
                    .then(res =>{
                        if(res.data.code == 200){
                            this.ShowMsg(res.data.msg,'success');
                                this.$emit('dataBind');
                                this.Closedialog();
                            }
                        })
                    .catch(err =>{
                        this.ShowMsg('服务器异常','error');
                    }).finally(()=>{
                            setTimeout(()=>{
                                loading.close();
                            },500);
                     })
                
                }
            } else {
                console.log('error submit!!');
                return false;
            }
            });
    }
  }
        
}
</script>

<style>
.dialog-footer{
    text-align: right;
}
</style>